﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using Peak.Core.DataInterfaces;
using Peak.Core;
using SharpArch.Data.NHibernate;
using NHibernate.LambdaExtensions;
using NHibernate.Criterion;
using System.Linq;

namespace Peak.Data
{
  public class ProjectRepository : NHibernateRepositoryWithTypedId<Project, int>,IProjectRepository
  {
    public IList<Project> GetAllByAssignedTo(string userName)
    {
      ICriteria c = Session.CreateCriteria(typeof(Project));
      c.CreateAlias("Users", "u");
      IList list = c.Add(Expression.InsensitiveLike("u.UserName",userName)).List();
      if (list.Count == 0)
        return new List<Project>();
      return list.OfType<Project>().ToList();
    }    
  }
}
